<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>进制转换和存储模型 | East'blog</title><meta name="author" content="侯玉东"><meta name="copyright" content="侯玉东"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="c++">
<meta property="og:type" content="article">
<meta property="og:title" content="进制转换和存储模型">
<meta property="og:url" content="https://houyudong1989.gitee.io/blog/2024/02/22/c++/2%E3%80%81%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2%E5%92%8C%E5%AD%98%E5%82%A8%E6%A8%A1%E5%9E%8B/index.html">
<meta property="og:site_name" content="East&#39;blog">
<meta property="og:description" content="c++">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://houyudong1989.gitee.io/blog/img/library1.jpeg">
<meta property="article:published_time" content="2024-02-22T02:00:29.871Z">
<meta property="article:modified_time" content="2024-02-23T01:20:31.933Z">
<meta property="article:author" content="侯玉东">
<meta property="article:tag" content="c++">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://houyudong1989.gitee.io/blog/img/library1.jpeg"><link rel="shortcut icon" href="/blog/img/head.jpg"><link rel="canonical" href="https://houyudong1989.gitee.io/blog/2024/02/22/c++/2%E3%80%81%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2%E5%92%8C%E5%AD%98%E5%82%A8%E6%A8%A1%E5%9E%8B/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/blog/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '进制转换和存储模型',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2024-02-23 09:20:31'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (true) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/blog/img/head.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">70</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友联</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg fixed" id="page-header" style="background-image: url('/blog/img/library6.jpeg')"><nav id="nav"><span id="blog-info"><a href="/blog/" title="East'blog"><img class="site-icon" src="/blog/img/head.jpg"/><span class="site-name">East'blog</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/link/"><i class="fa-fw fas fa-link"></i><span> 友联</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">进制转换和存储模型</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2024-02-22T02:00:29.871Z" title="发表于 2024-02-22 10:00:29">2024-02-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-02-23T01:20:31.933Z" title="更新于 2024-02-23 09:20:31">2024-02-23</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/c/">c++</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="进制转换和存储模型"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="进制概述"><a href="#进制概述" class="headerlink" title="进制概述"></a>进制概述</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">进制是一种用于表示数字的方法，常见的进制包括二进制（base-2）、八进制（base-8）、十进制（base-10）和十六进制（base-16）。每种进制都有对应的数字表示方式和计算规则。在计算机领域，二进制是最基础的进制，因为计算机内部使用的是二进制形式表示数据；八进制和十六进制常用于表示和处理数据；而十进制则是人们日常生活中最常用的进制。</span><br></pre></td></tr></table></figure>

<h2 id="二进制（Binary）"><a href="#二进制（Binary）" class="headerlink" title="二进制（Binary）"></a>二进制（Binary）</h2><blockquote>
<p>组成</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">只包含 0 和 1 两个数字，是计算机中最基础的进制。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>规则</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">逢2进1</span><br></pre></td></tr></table></figure>

<blockquote>
<p>示例</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">例如，1011 表示十进制的 11。</span><br></pre></td></tr></table></figure>

<h2 id="八进制（Octal）"><a href="#八进制（Octal）" class="headerlink" title="八进制（Octal）"></a>八进制（Octal）</h2><blockquote>
<p>组成</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">包含数字 0 到 7，每个八进制位相当于三个二进制位。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>规则</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">逢8进1</span><br></pre></td></tr></table></figure>

<blockquote>
<p>示例</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">例如，23 表示十进制的 19。</span><br></pre></td></tr></table></figure>

<h2 id="十进制（Decimal）"><a href="#十进制（Decimal）" class="headerlink" title="十进制（Decimal）"></a>十进制（Decimal）</h2><blockquote>
<p>组成</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">我们平常使用的数字系统，包含数字 0 到 9，每个位置代表 10 的幂次方。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>规则</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">逢10进1</span><br></pre></td></tr></table></figure>

<blockquote>
<p>示例</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">例如，123 表示 1 * 10^2 + 2 * 10^1 + 3 * 10^0 = 123。</span><br></pre></td></tr></table></figure>

<h2 id="十六进制（Hexadecimal）"><a href="#十六进制（Hexadecimal）" class="headerlink" title="十六进制（Hexadecimal）"></a>十六进制（Hexadecimal）</h2><blockquote>
<p>组成</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">包含数字 0 到 9 和字母 A 到 F（分别代表 10 到 15），常用于表示字节和颜色等。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>规则</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">逢16进1</span><br></pre></td></tr></table></figure>

<blockquote>
<p>示例</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">例如，1A 表示十进制的 26。</span><br></pre></td></tr></table></figure>

<h1 id="进制转换"><a href="#进制转换" class="headerlink" title="进制转换"></a>进制转换</h1><h2 id="十进制转其他进制"><a href="#十进制转其他进制" class="headerlink" title="十进制转其他进制"></a>十进制转其他进制</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使用短除法进行转换</span><br></pre></td></tr></table></figure>

<blockquote>
<p>十进制转二进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">将十进制数不断除以2，得到的余数即为二进制数的各个位数，最后将余数倒序排列即可得到二进制表示。例如，将十进制数13转换为二进制：13 ÷ 2 = 6 余 1，6 ÷ 2 = 3 余 0，3 ÷ 2 = 1 余 1，1 ÷ 2 = 0 余 1，所以13的二进制表示为1101</span><br></pre></td></tr></table></figure>

<blockquote>
<p>十进制转八进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">将十进制数不断除以8，得到的余数即为八进制数的各个位数，最后将余数倒序排列即可得到八进制表示。</span><br><span class="line">例如，将十进制数520转换为八进制：520 ÷ 8 = 65 余 0，65 ÷ 8 = 8 余 1，8 ÷ 8 = 1 余 0，1 ÷ 8 = 0 余 1 所以520的八进制表示为1010</span><br></pre></td></tr></table></figure>

<blockquote>
<p>十进制转十六进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">将十进制数不断除以16，得到的余数即为十六进制数的各个位数，对于大于9的余数，用A表示10、B表示11、C表示12、D表示13、E表示14、F表示15。最后将余数倒序排列即可得到十六进制表示。例如，将十进制数520转换为十六进制：520 ÷ 16 = 32 余 8，32 ÷ 16 = 2 余 0，2 ÷ 16 = 0 余 2， 所以520的八进制表示为208</span><br></pre></td></tr></table></figure>

<h2 id="其他进制转十进制"><a href="#其他进制转十进制" class="headerlink" title="其他进制转十进制"></a>其他进制转十进制</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使用位权相加进行转换</span><br></pre></td></tr></table></figure>

<blockquote>
<p>二进制转十进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">二进制（Binary）转换为十进制：将二进制数的每一位与2的幂相乘，然后将结果相加即可得到十进制数。例如，将二进制数1011转换为十进制：1×2^3 + 0×2^2 + 1×2^1 + 1×2^0 = 8 + 0 + 2 + 1 = 11。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>八进制转十进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">八进制（Octal）转换为十进制：将八进制数的每一位与8的幂相乘，然后将结果相加即可得到十进制数。</span><br><span class="line">例如，将八进制数1010转换为十进制：1×8^3 + 0×8^2 + 1×8^1 + 0×8^0 = 512 + 0 + 8 +0 = 520</span><br></pre></td></tr></table></figure>

<blockquote>
<p>十六进制转十进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">十六进制（Hexadecimal）转换为十进制：将十六进制数的每一位与16的幂相乘，然后将结果相加即可得到十进制数。需要注意的是，对于 A、B、C、D、E、F 这些表示大于9的数字，需要按照十进制数值进行计算。</span><br><span class="line">例如，将十六进制数208转换为十进制：2×16^2 + 0×16^1 + 8×16^0 = 512 + 0 + 8 = 520</span><br></pre></td></tr></table></figure>

<h2 id="其他进制相互转换"><a href="#其他进制相互转换" class="headerlink" title="其他进制相互转换"></a>其他进制相互转换</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">使用拆位的方式进行计算</span><br></pre></td></tr></table></figure>

<blockquote>
<p>二进制转八进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">二进制数中每三位代表八进制数中的一位，如下表示：</span><br><span class="line">二进制：1 000 001 000</span><br><span class="line">八进制：1  0   1   0</span><br></pre></td></tr></table></figure>

<blockquote>
<p>八进制转二进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">八进制数中的一位表示二进制数中的三位，如下表示：</span><br><span class="line">八进制：1  0   1   0</span><br><span class="line">二进制：1 000 001 000</span><br></pre></td></tr></table></figure>

<blockquote>
<p>二进制转十六进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">二进制数中每四位代表十六进制数中的一位，如下表示：</span><br><span class="line">二进制：  10 0000 1000</span><br><span class="line">十六进制： 2   0    8</span><br></pre></td></tr></table></figure>

<blockquote>
<p>十六进制转二进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">十六进制数中的一位表示二进制数中的四位，如下表示：</span><br><span class="line">十六进制： 2   0    8</span><br><span class="line">二进制：  10 0000 1000</span><br></pre></td></tr></table></figure>

<blockquote>
<p>八进制和十六进制</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">八进制和十六进制不能直接进行转换，可以先转换成二进制在进行转换</span><br></pre></td></tr></table></figure>

<h1 id="存储单位"><a href="#存储单位" class="headerlink" title="存储单位"></a>存储单位</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">计算机存储单位是用来衡量计算机内存容量的单位，它们用于表示数据存储和处理能力的大小。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>位（Bit）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">计算机存储的最小单位，取值为0或1。</span><br></pre></td></tr></table></figure>

<blockquote>
<p>字节（Byte）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">数据的最小存储单位，由8个位组成，如：00000001，是计算机中常用的基本存储单元。 </span><br><span class="line"></span><br><span class="line">1byte = 8bit</span><br></pre></td></tr></table></figure>

<blockquote>
<p>千字节（Kilobyte，KB）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">约等于1024字节，通常用来表示较小的文件大小或存储容量。</span><br><span class="line">1KB = 1024byte</span><br></pre></td></tr></table></figure>

<blockquote>
<p>兆字节（Megabyte，MB）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">约等于1024千字节，通常用来表示文件大小、照片、音频等媒体的容量。</span><br><span class="line">1MB = 1024KB</span><br></pre></td></tr></table></figure>

<blockquote>
<p>吉字节（Gigabyte，GB）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">约等于1024兆字节，通常用来表示大型文件、视频、软件等的容量。</span><br><span class="line">1GB = 1024MB</span><br></pre></td></tr></table></figure>

<blockquote>
<p>太字节（Terabyte，TB）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">约等于1024吉字节，通常用来表示大容量的数据存储，如硬盘、服务器等。</span><br><span class="line">1TB = 1024GB</span><br></pre></td></tr></table></figure>

<blockquote>
<p>拍字节（Petabyte，PB）</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">约等于1024太字节，用于描述非常庞大的数据存储。</span><br><span class="line">1PB = 1024TB</span><br><span class="line"> </span><br><span class="line">这些单位按照1024的倍数递增，表示不同级别的存储容量。在实际使用中，常用的是字节、千字节、兆字节和吉字节。</span><br></pre></td></tr></table></figure>

<h1 id="整数存储方式"><a href="#整数存储方式" class="headerlink" title="整数存储方式"></a>整数存储方式</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">计算机中的所有数都是通过二进制进行存储表示，叫做这个数的机器数。机器数是带符号的，在计算机用机器数的最高位存放符号，正数为0，负数为1。</span><br><span class="line">比如，十进制中的数+5， 计算机字长为8位，转换成二进制就是0000 0101，如果是-5 ，就是 100 00101 。</span><br><span class="line">那么，这里的 0000 0101 和 1000 0101 就是机器数。</span><br><span class="line"></span><br><span class="line">因为第一位是符号位，所以机器数的形式值就不等于真正的数值。</span><br><span class="line">例如上面的有符号数 1000 0101，其最高位1代表负，其真正数值是 -5，而不是形式值133（1000 0101转换成十进制等于133）。所以，为区别起见，将带符号位的机器数对应的真正数值称为机器数的真值。</span><br><span class="line"></span><br><span class="line">例：0000 0001的真值 = +000 0001 = +1，1000 0001的真值 = –000 0001 = –1</span><br></pre></td></tr></table></figure>

<h2 id="原码"><a href="#原码" class="headerlink" title="原码"></a>原码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">原码就是机器数，即用第一位表示符号，其余位表示值。比如：如果是8位二进制：</span><br><span class="line"></span><br><span class="line">[+1]原= 0000 0001</span><br><span class="line"></span><br><span class="line">[-1]原= 1000 0001</span><br><span class="line"></span><br><span class="line">第一位是符号位，因为第一位是符号位，所以8位二进制数的取值范围就是：（即第一位不表示值，只表示正负。）</span><br><span class="line"></span><br><span class="line">[1111 1111 , 0111 1111]   即   [-127 , 127]</span><br><span class="line"></span><br><span class="line">原码是人脑最容易理解和计算的表示方式。</span><br></pre></td></tr></table></figure>

<h2 id="反码"><a href="#反码" class="headerlink" title="反码"></a>反码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">正数的反码是其本身；</span><br><span class="line">负数的反码是在其原码的基础上，符号位不变，其余各个位取反。</span><br><span class="line"></span><br><span class="line">[+1] = [0000 0001]原 = [0000 0001]反</span><br><span class="line"></span><br><span class="line">[-1] = [1000 0001]原 = [1111 1110]反</span><br><span class="line"></span><br><span class="line">可见如果一个反码表示的是负数，人脑无法直观的看出来它的数值。通常要将其转换成原码再计算。</span><br></pre></td></tr></table></figure>

<h2 id="补码"><a href="#补码" class="headerlink" title="补码"></a>补码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">正数的补码就是其本身；</span><br><span class="line">负数的补码是在其原码的基础上，符号位不变，其余各位取反，最后+1。(也即在反码的基础上+1)</span><br><span class="line"></span><br><span class="line">[+1] = [0000 0001]原 = [0000 0001]反 = [0000 0001]补</span><br><span class="line"></span><br><span class="line">[-1] = [1000 0001]原 = [1111 1110]反 = [1111 1111]补</span><br><span class="line"></span><br><span class="line">对于负数，补码表示方式也是人脑无法直观看出其数值的。通常也需要转换成原码再计算其数值。</span><br></pre></td></tr></table></figure>

<h2 id="为何要使用原码、反码和补码"><a href="#为何要使用原码、反码和补码" class="headerlink" title="为何要使用原码、反码和补码"></a>为何要使用原码、反码和补码</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">人脑可以知道第一位是符号位，在计算的时候我们会根据符号位，选择对真值区域的加减。(真值的概念在本文最开头) 但是对于计算机，加减乘数已经是最基础的运算，要设计的尽量简单，计算机辨别&quot;符号位&quot;显然会让计算机的基础电路设计变得十分复杂！</span><br><span class="line">于是人们想出了将符号位也参与运算的方法。我们知道，根据运算法则减去一个正数等于加上一个负数，即：1-1 = 1 + (-1) = 0， 所以机器可以只有加法而没有减法，这样计算机运算的设计就更简单了。</span><br></pre></td></tr></table></figure>

<ul>
<li>我们以计算十进制表达式：1 - 1 &#x3D;  0为例</li>
</ul>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">1、首先来看原码： </span><br><span class="line"></span><br><span class="line">    1 - 1 = 1 + (-1) = [0000 0001]原+ [1000 0001]原= [1000 0010]原= -2</span><br><span class="line"></span><br><span class="line">如果用原码表示，让符号位也参与计算，显然对于减法来说，结果是不正确的。这也就是为何计算机内部不使用原码表示一个数。</span><br><span class="line"></span><br><span class="line">2、为了解决原码做减法的问题， 出现了反码： </span><br><span class="line"></span><br><span class="line">    1 - 1 = 1 + (-1) = [0000 0001]原+ [1000 0001]原= [0000 0001]反+ [1111 1110]反= [1111 1111]反= [1000 0000]原= -0</span><br><span class="line"></span><br><span class="line">发现用反码计算减法，结果的真值部分是正确的。而唯一的问题其实就出现在&quot;0&quot;这个特殊的数值上，虽然人们理解上 +0和-0 是一样的，但是0带符号是没有任何意义的，而且会有[0000 0000]原和[1000 0000]原两个编码表示0。</span><br><span class="line"></span><br><span class="line">3、于是补码的出现，解决了0的符号问题以及0的两个编码问题： </span><br><span class="line"></span><br><span class="line">    1-1 = 1 + (-1) = [0000 0001]原+ [1000 0001]原= [0000 0001]补+ [1111 1111]补= [1 0000 0000]补=[0000 0000]补=[0000 0000]原注意：进位1不在计算机字长里。</span><br><span class="line"></span><br><span class="line">这样0用[0000 0000]表示，而以前出现问题的-0则不存在了。而且可以用[1000 0000]表示-128：</span><br><span class="line"></span><br><span class="line">4、-128的由来如下：</span><br><span class="line"></span><br><span class="line">    (-1) + (-127) = [1000 0001]原+ [1111 1111]原= [1111 1111]补+ [1000 0001]补= [1000 0000]补</span><br><span class="line"></span><br><span class="line">-1-127的结果应该是-128，在用补码运算的结果中，[1000 0000]补就是-128，但是注意因为实际上是使用以前的-0的补码来表示-128，所以-128并没有原码和反码表示。(对-128的补码表示[1000 0000]补，算出来的原码是[0000 0000]原，这是不正确的)</span><br><span class="line"></span><br><span class="line">使用补码，不仅仅修复了0的符号以及存在两个编码的问题，而且还能够多表示一个最低数。这就是为什么8位二进制，使用原码或反码表示的范围为[-127, +127]，而使用补码表示的范围为[-128, 127]。</span><br><span class="line"></span><br><span class="line">整数的存储是将十进制为的整数转换成其相应的补码后存储。</span><br></pre></td></tr></table></figure>

<h1 id="小数的存储方式"><a href="#小数的存储方式" class="headerlink" title="小数的存储方式"></a>小数的存储方式</h1><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">现如今的计算机中浮点数的存储都是遵循IEEE754/854标准，以二进制的科学计数法存放到内存中。</span><br><span class="line"></span><br><span class="line">对于浮点数在计算机中有两种存储的精度，即单精度和双精度，单精度是32位，双精度是64位。</span><br></pre></td></tr></table></figure>

<p><img src="1708612708766.png" alt="1708612708766"></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">+ 符号S：0为正，1为负</span><br><span class="line">+ 尾数M：小数点后面的部分</span><br><span class="line">+ 指数E：即阶码，指明了小数点在数据中的位置</span><br><span class="line">  + 为了让指数表示正、负引入了偏差码，float的为127,double的为1024</span><br></pre></td></tr></table></figure>

<p><strong>十进制小数转二进制小数</strong></p>
<ul>
<li>先把整数部分转化为二进制</li>
<li>再把小数部分转化为二进制(用2乘以小数部分，每次将结果整数取出，然后用剩余小数部分继续乘以2，直到小数部分为零，或者达到要求的精度为止)</li>
</ul>
<blockquote>
<p>以float f &#x3D; 5.25为例</p>
</blockquote>
<p>整数部分：5       -&gt; 101</p>
<p>小数部分：0.25  -&gt;  0.01</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0.25</span> * <span class="number">2</span> = <span class="number">0.5</span>  --- <span class="number">0</span></span><br><span class="line"><span class="number">0.5</span>  * <span class="number">2</span> = <span class="number">1.0</span>  --- <span class="number">1</span>  </span><br><span class="line">从上往下取值：<span class="number">0.01</span>  </span><br></pre></td></tr></table></figure>

<p>最后结果：101.01 &#x3D; 1.0101 * 2^2</p>
<p>可见指数实际值为2，加上偏差码127，2 + 127 &#x3D; 129，129的二进制为10000001B，因此不难得到，8.25在内存中的存储情况为:</p>
<table>
<thead>
<tr>
<th align="center">S</th>
<th align="center">E</th>
<th align="center">M</th>
</tr>
</thead>
<tbody><tr>
<td align="center">0</td>
<td align="center">1000 0001</td>
<td align="center">0101 0000 0000 0000 0000 000</td>
</tr>
</tbody></table>
<p><strong>如果把这个值作为整型使用，将是一个很大的数字，是1084751872</strong></p>
<p>把这个内存里面的值转为十进制小数就很简单了：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//1,首先判断S表示的正负      +</span></span><br><span class="line"><span class="comment">//2，计算出E实际表示的指数   1000 0001 = 129    129 - 127 = 2</span></span><br><span class="line"><span class="comment">//3，根据M写出二进制小数形式  1.0101 * 2^2  = 101.01</span></span><br><span class="line"><span class="comment">//4，对二进制小数以小数点为界限开始编号</span></span><br><span class="line"><span class="number">210</span> <span class="number">-1</span><span class="number">-2</span> 编号</span><br><span class="line"><span class="number">101.</span> <span class="number">0</span> <span class="number">1</span> B</span><br><span class="line"><span class="number">1</span>*<span class="number">2</span>^<span class="number">2</span> + <span class="number">0</span> + <span class="number">1</span>*<span class="number">2</span>^<span class="number">0</span> + <span class="number">0</span>*<span class="number">2</span>^(<span class="number">-1</span>) + <span class="number">1</span>*<span class="number">2</span>^(<span class="number">-2</span>) = <span class="number">4</span> + <span class="number">1</span> +  <span class="number">0.25</span> =<span class="number">5.25</span>   </span><br></pre></td></tr></table></figure>

<p><strong>注意：</strong></p>
<ul>
<li>在二进制，第一个有效数字必定是“1”，因此这个“1”并不会存储。</li>
<li>浮点数不能精确表示其范围内的所有数。</li>
<li>可精确表示的数不是均匀分布的，越靠近0越稠密。</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="https://houyudong1989.gitee.io/blog">侯玉东</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="https://houyudong1989.gitee.io/blog/2024/02/22/c++/2%E3%80%81%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2%E5%92%8C%E5%AD%98%E5%82%A8%E6%A8%A1%E5%9E%8B/">https://houyudong1989.gitee.io/blog/2024/02/22/c++/2%E3%80%81%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2%E5%92%8C%E5%AD%98%E5%82%A8%E6%A8%A1%E5%9E%8B/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://houyudong1989.gitee.io/blog" target="_blank">East'blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/c/">c++</a></div><div class="post_share"><div class="social-share" data-image="/blog/img/library1.jpeg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/2024/02/23/c++/0%E3%80%81%E5%9F%BA%E7%A1%80%E5%86%85%E5%AE%B9/" title="基础内容"><img class="cover" src="/blog/img/library1.jpeg" onerror="onerror=null;src='/blog/img/friend_404.gif'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">基础内容</div></div></a></div><div class="next-post pull-right"><a href="/blog/2024/02/04/kotlin/kotlin%E5%9F%BA%E7%A1%80/" title="kotlin基础-基本类型"><img class="cover" src="/blog/img/library1.jpeg" onerror="onerror=null;src='/blog/img/friend_404.gif'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">kotlin基础-基本类型</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/blog/2023/12/09/c++/%E7%BC%96%E8%AF%91gmp%E5%92%8Cmpfr/" title=""><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-09</div><div class="title"></div></div></a></div><div><a href="/blog/2023/12/13/c++/%E5%BC%80%E5%8F%91%E8%BF%87%E7%A8%8B%E4%B8%AD%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98/cmake%E7%BC%96%E8%AF%91%E5%A4%B1%E8%B4%A5/" title="cmake编译失败"><img class="cover" src="/blog/img/library1.jpeg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-12-13</div><div class="title">cmake编译失败</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/blog/img/head.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">侯玉东</div><div class="author-info__description">生命不息，奋斗不止</div></div><div class="card-info-data site-data is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">70</div></a><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">26</div></a><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">18</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/houyudong1989"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/houyudong1989" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:420098321@qq.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎来到我的博客！！！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BF%9B%E5%88%B6%E6%A6%82%E8%BF%B0"><span class="toc-number">1.</span> <span class="toc-text">进制概述</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%8C%E8%BF%9B%E5%88%B6%EF%BC%88Binary%EF%BC%89"><span class="toc-number">1.1.</span> <span class="toc-text">二进制（Binary）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%AB%E8%BF%9B%E5%88%B6%EF%BC%88Octal%EF%BC%89"><span class="toc-number">1.2.</span> <span class="toc-text">八进制（Octal）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%81%E8%BF%9B%E5%88%B6%EF%BC%88Decimal%EF%BC%89"><span class="toc-number">1.3.</span> <span class="toc-text">十进制（Decimal）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%81%E5%85%AD%E8%BF%9B%E5%88%B6%EF%BC%88Hexadecimal%EF%BC%89"><span class="toc-number">1.4.</span> <span class="toc-text">十六进制（Hexadecimal）</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.</span> <span class="toc-text">进制转换</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%81%E8%BF%9B%E5%88%B6%E8%BD%AC%E5%85%B6%E4%BB%96%E8%BF%9B%E5%88%B6"><span class="toc-number">2.1.</span> <span class="toc-text">十进制转其他进制</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E8%BF%9B%E5%88%B6%E8%BD%AC%E5%8D%81%E8%BF%9B%E5%88%B6"><span class="toc-number">2.2.</span> <span class="toc-text">其他进制转十进制</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B6%E4%BB%96%E8%BF%9B%E5%88%B6%E7%9B%B8%E4%BA%92%E8%BD%AC%E6%8D%A2"><span class="toc-number">2.3.</span> <span class="toc-text">其他进制相互转换</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AD%98%E5%82%A8%E5%8D%95%E4%BD%8D"><span class="toc-number">3.</span> <span class="toc-text">存储单位</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B4%E6%95%B0%E5%AD%98%E5%82%A8%E6%96%B9%E5%BC%8F"><span class="toc-number">4.</span> <span class="toc-text">整数存储方式</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8E%9F%E7%A0%81"><span class="toc-number">4.1.</span> <span class="toc-text">原码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%8D%E7%A0%81"><span class="toc-number">4.2.</span> <span class="toc-text">反码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%A1%A5%E7%A0%81"><span class="toc-number">4.3.</span> <span class="toc-text">补码</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%BA%E4%BD%95%E8%A6%81%E4%BD%BF%E7%94%A8%E5%8E%9F%E7%A0%81%E3%80%81%E5%8F%8D%E7%A0%81%E5%92%8C%E8%A1%A5%E7%A0%81"><span class="toc-number">4.4.</span> <span class="toc-text">为何要使用原码、反码和补码</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B0%8F%E6%95%B0%E7%9A%84%E5%AD%98%E5%82%A8%E6%96%B9%E5%BC%8F"><span class="toc-number">5.</span> <span class="toc-text">小数的存储方式</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/06/c++/5%E3%80%81%E5%AD%97%E7%AC%A6%E5%92%8C%E5%AD%97%E7%AC%A6%E4%B8%B2/" title="字符和字符串"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="字符和字符串"/></a><div class="content"><a class="title" href="/blog/2024/05/06/c++/5%E3%80%81%E5%AD%97%E7%AC%A6%E5%92%8C%E5%AD%97%E7%AC%A6%E4%B8%B2/" title="字符和字符串">字符和字符串</a><time datetime="2024-05-06T11:15:27.280Z" title="发表于 2024-05-06 19:15:27">2024-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/06/c++/4%E3%80%81%E6%8C%87%E9%92%88%E5%92%8C%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88/" title="指针和函数指针"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="指针和函数指针"/></a><div class="content"><a class="title" href="/blog/2024/05/06/c++/4%E3%80%81%E6%8C%87%E9%92%88%E5%92%8C%E5%87%BD%E6%95%B0%E6%8C%87%E9%92%88/" title="指针和函数指针">指针和函数指针</a><time datetime="2024-05-06T11:14:29.047Z" title="发表于 2024-05-06 19:14:29">2024-05-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/05/05/python/7%E3%80%81m3u8%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F/" title="m3u8格式"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="m3u8格式"/></a><div class="content"><a class="title" href="/blog/2024/05/05/python/7%E3%80%81m3u8%E8%A7%86%E9%A2%91%E6%A0%BC%E5%BC%8F/" title="m3u8格式">m3u8格式</a><time datetime="2024-05-05T01:43:26.865Z" title="发表于 2024-05-05 09:43:26">2024-05-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/04/30/android/charles%E5%AE%89%E5%8D%93%E6%89%8B%E6%9C%BA%E6%8A%93%E5%8C%85/" title="charles 抓包"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="charles 抓包"/></a><div class="content"><a class="title" href="/blog/2024/04/30/android/charles%E5%AE%89%E5%8D%93%E6%89%8B%E6%9C%BA%E6%8A%93%E5%8C%85/" title="charles 抓包">charles 抓包</a><time datetime="2024-04-30T06:49:29.279Z" title="发表于 2024-04-30 14:49:29">2024-04-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/2024/04/26/python/13%E3%80%81playwright/" title="playwright"><img src="/blog/img/library1.jpeg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="playwright"/></a><div class="content"><a class="title" href="/blog/2024/04/26/python/13%E3%80%81playwright/" title="playwright">playwright</a><time datetime="2024-04-26T07:30:36.069Z" title="发表于 2024-04-26 15:30:36">2024-04-26</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By 侯玉东</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><div class="aplayer no-destroy" data-id="8873950678" data-server="netease" data-type="playlist" data-fixed="true" data-autoplay="true"> </div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener
  btf.removeGlobalFnEvent('pjax')
  btf.removeGlobalFnEvent('themeChange')

  document.getElementById('rightside').classList.remove('rightside-show')
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', e => {
  if (e.request.status === 404) {
    pjax.loadUrl('/blog/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>